package com.hzhr.iot.device.service;

import com.hzhr.iot.collect.sdk.model.command.addMeter.AddMeterModel;
import com.hzhr.iot.collect.sdk.model.command.addMeter.AddMeterResponse;
import com.hzhr.iot.collect.sdk.model.command.delMeter.DelMeterModel;
import com.hzhr.iot.collect.sdk.model.command.jichao.JichaoModel;
import com.hzhr.iot.collect.sdk.service.Collect_CommandService;
import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.CygQuery;
import com.hzhr.iot.core.annotation.CygQuerys;
import com.hzhr.iot.core.annotation.CygService;
import com.hzhr.iot.core.constant.AccessModeEnum;
import com.hzhr.iot.core.constant.CommonOptions;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.core.util.HzhrTypeUtil;
import com.hzhr.iot.device.constant.DeviceOptions;
import com.hzhr.iot.device.constant.Device_ErrorsEnum;
import com.hzhr.iot.device.convertor.custom.CollectDeviceCustomConvertor;
import com.hzhr.iot.device.convertor.custom.IotDeviceCustomConvertor;
import com.hzhr.iot.device.dao.CollectDeviceDao;
import com.hzhr.iot.device.dao.IotDeviceDao;
import com.hzhr.iot.device.dao.helper.CollectDeviceDaoHelper;
import com.hzhr.iot.device.entity.CollectDeviceEntity;
import com.hzhr.iot.device.entity.ext.CollectDeviceEntityExt;
import com.hzhr.iot.device.entity.ext.IotDeviceEntityExt;
import com.hzhr.iot.device.model.concentrator_meter.*;
import com.hzhr.iot.device.queryModel.custom.CollectDataCustomQueryModel;
import com.hzhr.iot.device.queryModel.custom.CollectDeviceCustomQueryModel;
import com.hzhr.iot.device.queryModel.custom.IotDeviceCustomQueryModel;
import com.hzhr.iot.device.service.base.BaseService;
import com.hzhr.iot.login.sdk.model.userCard.UserCardModel;
import com.hzhr.iot.user.sdk.model.dept.DeptGetModel;
import com.hzhr.iot.user.sdk.model.dept.DeptModel;
import com.hzhr.iot.user.sdk.service.User_DeptService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.*;

@Service
@CygService(entity = CollectDeviceEntity.class, model = Concentrator_MeterModel.class)
@CygQuerys({
        @CygQuery(name = "_equal_id", query = "equal_id", type = Integer.class),
        @CygQuery(name = "_equal_code", query = "equal_code", type = String.class),
        @CygQuery(name = "_like_des", query = "like_des", type = String.class),
        @CygQuery(name = "_greaterthanorequal_createTime", query = "greaterthanorequal_createTime", type = Date.class),
        @CygQuery(name = "_lessthan_createTime", query = "lessthan_createTime", type = Date.class),
})
public class Concentrator_MeterService extends BaseService {

    @Autowired
    CollectDeviceCustomConvertor collectDeviceCustomConvertor;

    @Autowired
    DeviceOptions deviceOptions;

    @Autowired
    IotDeviceDao iotDeviceDao;

    @Autowired
    CollectDeviceDao collectDeviceDao;

    @Autowired
    IotDeviceCustomConvertor iotDeviceCustomConvertor;

    @Autowired
    User_DeptService user_deptService;

    @Autowired
    Collect_CommandService collect_commandService;

    @Autowired
    CollectDeviceDaoHelper collectDeviceDaoHelper;

    //region javadoc注释 : postByConcentratorId
    /**
     * 在用户所在物联设备公司下的集中器下新增表具 <br/><br/>
     * 步骤 : <br/>
     * 1. 查询集中器：在用户所在的物联网公司下查询集中器,如果集中器不存在，抛出异常“集中器不存在” <br/>
     * 2. 验证表具代码：表具代码全局唯一 <br/>
     * 3. 创建表具：在集中器下创建表具 <br/>
     * 4. 发送指令到集中器：如果该集中器使用的是“重燃集中器协议”，须发送“增加下级表具”指令到集中器 <br/>
     * 5. 返回信息 <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/><br/>
     * @param concentratorId 集中器编号 <br/><br/>
     * @param body <br/><br/>
     * @throws ServiceException <br/>
     * CONCENTRATOR_METERSERVICE_POST_BY_CONCENTRATOR_ID_201 : <br/>&nbsp&nbsp&nbsp&nbsp异常类型 : 业务流程异常<br/>&nbsp&nbsp&nbsp&nbsp异常业务 : 查询集中器<br/>&nbsp&nbsp&nbsp&nbsp异常描述 : 集中器不存在<br/>
     * CONCENTRATOR_METERSERVICE_POST_BY_CONCENTRATOR_ID_202 : <br/>&nbsp&nbsp&nbsp&nbsp异常类型 : 业务流程异常<br/>&nbsp&nbsp&nbsp&nbsp异常业务 : 验证表具代码<br/>&nbsp&nbsp&nbsp&nbsp异常描述 : 表具代码已存在<br/>
     * @see Concentrator_MeterPostModel body <br/>
     * @see Concentrator_MeterGetModel result <br/>
     */ 
    //endregion
    //region 说明 : postByConcentratorId
    //在用户所在物联设备公司下的集中器下新增表具
    //步骤 :
    //1. 查询集中器：在用户所在的物联网公司下查询集中器,如果集中器不存在，抛出异常“集中器不存在”
    //2. 验证表具代码：表具代码全局唯一
    //3. 创建表具：在集中器下创建表具
    //4. 发送指令到集中器：如果该集中器使用的是“重燃集中器协议”，须发送“增加下级表具”指令到集中器
    //5. 返回信息
    //endregion
    //region 参数 : postByConcentratorId
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "concentratorId", value = "集中器编号",required = true, dataType = "int", paramType = "path"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    //endregion
    //region 请求 : postByConcentratorId
    @RequestMapping(value = "/concentrators/{concentratorId}/meters", method = RequestMethod.POST)
    //endregion
    public Concentrator_MeterGetModel postByConcentratorId(Map<String, String> header, Integer concentratorId,
                                                           Map<String, Object> query, Concentrator_MeterPostModel body) throws ServiceException {
        /* 查询集中器：在用户所在的物联网公司下查询集中器,如果集中器不存在，抛出异常“集中器不存在” */
        UserCardModel userCard = getUserCard(header);
        IotDeviceCustomQueryModel queryModel = new IotDeviceCustomQueryModel();
        queryModel.setEqual_id(concentratorId);
        queryModel.setEqual_companyId(userCard.getCompanyId());
        queryModel.setEqual_categoryCode(deviceOptions.getCode("IOT_DEVICE_CATEGORY","CONCENTRATOR"));
        queryModel.setEqual_isValid("1");
        queryModel.setShow(true);
        IotDeviceEntityExt iotDevice_1 = iotDeviceDao.selectExt(queryModel);
        if (iotDevice_1 == null){
            throw new ServiceException(Device_ErrorsEnum.CONCENTRATOR_METERSERVICE_POST_BY_CONCENTRATOR_ID_201);
        }

        /* 验证表具代码：表具代码全局唯一 */
        CollectDeviceCustomQueryModel queryModel1 = collectDeviceCustomConvertor.collectDeviceService_query2queryModel(query);
        queryModel1.setEqual_code(body.getCode());
        queryModel1.setEqual_isValid("1");
        CollectDeviceEntity collectDeviceEntity = collectDeviceDao.selectEntity(queryModel1);
        if (collectDeviceEntity != null){
            throw new ServiceException(Device_ErrorsEnum.CONCENTRATOR_METERSERVICE_POST_BY_CONCENTRATOR_ID_202);
        }

        /* 创建表具：在集中器下创建表具 */
        CollectDeviceEntity collectDevice_1 = collectDeviceCustomConvertor.concentrator_MeterPostModel2entity(body);
        collectDevice_1.setCategoryCode(deviceOptions.getCode("COLLECT_DEVICE_CATEGORY","LORA_METER"));
        collectDevice_1.setCompanyId(iotDevice_1.getGasCompanyId());
        collectDevice_1.setDeptId(iotDevice_1.getDeptId());
        collectDevice_1.setIotDeviceId(iotDevice_1.getId());
        collectDevice_1.setCreateUserId(userCard.getUserId());
        collectDevice_1.setCreateTime(new Date());
        collectDevice_1.setIsValid(CommonOptions.YES_NO.YES);
        collectDevice_1.setState("1");

        Integer deptId = iotDevice_1.getDeptId();
        //关联关系：IotDeviceEntityExt.deptId = DeptModel.id)
        Map<String, Object> query1 = new HashMap<>();
        query1.put("_equal_id", deptId);
        query1.put("_show", "one");
        query1.put("_show_info", true);
        DeptGetModel deptGetModel = user_deptService.get(initHeader(header, AccessModeEnum.GLOBAL), query1);
        if (deptGetModel != null) {
            DeptModel dept_1 = deptGetModel.getModel();
            if (dept_1 != null) {
                collectDevice_1.setResourceCode(dept_1.getResourceCode());
            }
        }
        int changeCount = collectDeviceDao.insert(collectDevice_1);

        /* 发送指令到集中器：如果该集中器使用的是“重燃集中器协议”，须发送“增加下级表具”指令到集中器 */
        String protocolId = iotDevice_1.getProtocolId();
        if (protocolId == null || protocolId.equals("2")) {
            Map<String, Object> query2 = new HashMap<>();
            AddMeterModel addMeterModel = new AddMeterModel();
            addMeterModel.setDeviceId(iotDevice_1.getIotPlatformDeviceId());
            addMeterModel.setMeterNo(collectDevice_1.getCode());
            collect_commandService.ccr_addMeter(initHeader(header, AccessModeEnum.GLOBAL), 2, query2, addMeterModel);
        }

        /* 返回信息 */
        CollectDeviceCustomQueryModel queryModel2 = new CollectDeviceCustomQueryModel();
        queryModel2.setEqual_id(collectDevice_1.getId());
        Boolean showInfo = HzhrTypeUtil.object2boolean(query.get("_show_info"));
        if (showInfo != null && showInfo) {
            queryModel2.setShow(true);
        }

        List<CollectDeviceEntityExt> collectDeviceEntityExt = null;
        String _show = HzhrTypeUtil.object2string(query.get("_show"));
        if (_show != null) {
             collectDeviceEntityExt = collectDeviceDao.selectExtList(queryModel2);
        }


        Boolean _show_total = HzhrTypeUtil.object2boolean(query.get("_show_total"));
//        Concentrator_MeterGetModel result = collectDeviceCustomConvertor.extList2concentrator_MeterGetModel(list,null,changeCount,query);
        Concentrator_MeterGetModel result = new Concentrator_MeterGetModel();
        if ("one".equals(_show)) {
            CollectDeviceEntityExt collectDeviceEntityExt1 = collectDeviceEntityExt.get(0);
            Concentrator_MeterModel concentrator_meterModel = new Concentrator_MeterModel();
            concentrator_meterModel.setCode(collectDeviceEntityExt1.getCode());
            concentrator_meterModel.setCreateTime(HzhrTypeUtil.date2long(collectDeviceEntityExt1.getCreateTime()));
            concentrator_meterModel.setDes(collectDeviceEntityExt1.getDes());
            concentrator_meterModel.setId(collectDeviceEntityExt1.getId());
            result.setModel(concentrator_meterModel);

        }
        if ("list".equals(_show)) {
            List<Concentrator_MeterModel> concentrator_meterModels_1 = new ArrayList<>();
            for ( CollectDeviceEntityExt collectDeviceEntityExts : collectDeviceEntityExt){
                Concentrator_MeterModel concentrator_meterModel = new Concentrator_MeterModel();
                concentrator_meterModel.setCode(collectDeviceEntityExts.getCode());
                concentrator_meterModel.setCreateTime(HzhrTypeUtil.date2long(collectDeviceEntityExts.getCreateTime()));
                concentrator_meterModel.setDes(collectDeviceEntityExts.getDes());
                concentrator_meterModel.setId(collectDeviceEntityExts.getId());
                concentrator_meterModels_1.add(concentrator_meterModel);
                result.setModelList(concentrator_meterModels_1);
            }
        }

        result.setChangeCount(changeCount);
        return result;
    }


    //region javadoc注释 : putByConcentratorIdAndId
    /**
     * 在用户所在物联设备公司下的集中器下修改表具 <br/><br/>
     * 简介 : 在用户所在物联设备公司下的集中器下修改表具 <br/>
     * 步骤 : <br/>
     * 1. 查询集中器下的表具： <br/>
     * 查询CollectDeviceEntityExt对象colletDevice_1, 筛选规则如下： <br/>
     *           CollectDeviceEntityExt.id = 路径参数id； <br/>
     *           CollectDeviceEntityExt.iotDeviceId = 路径参数concentratorId； <br/>
     *           CollectDeviceEntityExt.categoryCode = deviceOptions.getCode('COLLECT_DEVICE_CATEGORY','LORA_METER')； <br/>
     *           CollectDeviceEntityExt.iotDeviceExt.companyId = 登录用户.companyId； <br/>
     * 如果collectDevice_1不存在，抛出异常201； <br/>
     * 2. 验证修改信息 : <br/>
     * (1) 验证表具代码： <br/>
     *           如果body.code != colletDevice_1.code，并且存在CollectDeviceEntity对象满足以下条件，则抛出异常202： <br/>
     *               CollectDeviceEntity.code = body.code； <br/>
     * 3. 更新表具 : <br/>
     * 根据body更新collectDevice_1； <br/>
     * 4. 返回信息 : <br/>
     * 根据条件参数查询更新后的collectDevice_1，然后根据查询结果组装结果对象并返回； <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/><br/>
     * @param concentratorId 集中器编号 <br/><br/>
     * @param id 编号 <br/><br/>
     * @param body <br/><br/>
     * @throws ServiceException <br/>
     * CONCENTRATOR_METERSERVICE_PUT_BY_CONCENTRATOR_ID_AND_ID_201 : <br/>&nbsp&nbsp&nbsp&nbsp异常类型 : 业务流程异常<br/>&nbsp&nbsp&nbsp&nbsp异常业务 : 查询集中器下的表具<br/>&nbsp&nbsp&nbsp&nbsp异常描述 : 查询集中器下的表具不存在<br/>
     * CONCENTRATOR_METERSERVICE_PUT_BY_CONCENTRATOR_ID_AND_ID_202 : <br/>&nbsp&nbsp&nbsp&nbsp异常类型 : 业务流程异常<br/>&nbsp&nbsp&nbsp&nbsp异常业务 : 验证修改信息<br/>&nbsp&nbsp&nbsp&nbsp异常描述 : 表具代码已存在<br/>
     * @see Concentrator_MeterPutModel body <br/>
     * @see Concentrator_MeterGetModel result <br/>
     */ 
    //endregion
    //region 说明 : putByConcentratorIdAndId
    //在用户所在物联设备公司下的集中器下修改表具
    //简介 : 在用户所在物联设备公司下的集中器下修改表具
    //步骤 :
    //1. 查询集中器下的表具：
    //查询CollectDeviceEntityExt对象colletDevice_1, 筛选规则如下：
    //          CollectDeviceEntityExt.id = 路径参数id；
    //          CollectDeviceEntityExt.iotDeviceId = 路径参数concentratorId；
    //          CollectDeviceEntityExt.categoryCode = deviceOptions.getCode('COLLECT_DEVICE_CATEGORY','LORA_METER')；
    //          CollectDeviceEntityExt.iotDeviceExt.companyId = 登录用户.companyId；
    //如果collectDevice_1不存在，抛出异常201；
    //2. 验证修改信息 :
    //(1) 验证表具代码：
    //          如果body.code != colletDevice_1.code，并且存在CollectDeviceEntity对象满足以下条件，则抛出异常202：
    //              CollectDeviceEntity.code = body.code；
    //3. 更新表具 :
    //根据body更新collectDevice_1；
    //4. 返回信息 :
    //根据条件参数查询更新后的collectDevice_1，然后根据查询结果组装结果对象并返回；
    //endregion
    //region 参数 : putByConcentratorIdAndId
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "concentratorId", value = "集中器编号",required = true, dataType = "int", paramType = "path"),
            @ApiImplicitParam(name = "id", value = "编号",required = true, dataType = "int", paramType = "path"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    //endregion
    //region 请求 : putByConcentratorIdAndId
    @RequestMapping(value = "/concentrators/{concentratorId}/meters/{id}", method = RequestMethod.PUT)
    //endregion
    public Concentrator_MeterGetModel putByConcentratorIdAndId(Map<String, String> header, Integer concentratorId, Integer id,
                                                               Map<String, Object> query, Concentrator_MeterPutModel body) throws ServiceException {

        //1. 查询集中器下的表具
        UserCardModel userCardModel = getUserCard(header);
        CollectDeviceCustomQueryModel queryModel = new CollectDeviceCustomQueryModel();
        queryModel.setEqual_id(id);
        queryModel.setEqual_iotDeviceId(concentratorId);
        queryModel.setEqual_categoryCode(deviceOptions.getCode("COLLECT_DEVICE_CATEGORY","LORA_METER"));
        queryModel.setEqual_iotDeviceExt_companyId(userCardModel.getCompanyId());
        queryModel.setEqual_isValid("1");
        queryModel.setShow(true);
        CollectDeviceEntityExt collectDevice_1 = null;
        collectDevice_1 = collectDeviceDao.selectExt(queryModel);
        if (collectDevice_1 == null){
            throw new ServiceException(Device_ErrorsEnum.CONCENTRATOR_METERSERVICE_PUT_BY_CONCENTRATOR_ID_AND_ID_201);
        }
        //2. 验证修改信息
        CollectDeviceCustomQueryModel queryModel1 = new CollectDeviceCustomQueryModel();
        queryModel1.setEqual_code(body.getCode());
        int Count = collectDeviceDao.selectCount(queryModel1);
        if (body != null){
            if (!body.getCode().equals(collectDevice_1.getCode()) && Count > 0){
                throw new ServiceException(Device_ErrorsEnum.CONCENTRATOR_METERSERVICE_PUT_BY_CONCENTRATOR_ID_AND_ID_202);
            }
        }

        //3. 更新表具
//        CollectDeviceEntity collectDevice_2 = collectDeviceCustomConvertor.concentrator_MeterPutModel2entity(body);
//        CollectDeviceEntityExt collectDevice_2 = new CollectDeviceEntityExt();
        collectDevice_1.setCode(body.getCode());
        collectDevice_1.setDes(body.getDes());
        int ChangeCount = collectDeviceDao.update(collectDevice_1);


        //4. 返回信息
        //根据条件参数查询更新后的collectDevice_1，然后根据查询结果组装结果对象并返回；
        query.put("_equal_id", collectDevice_1.getId());
        CollectDeviceCustomQueryModel queryModel2 = collectDeviceCustomConvertor.concentrator_MeterService_query2queryModel(query);

        CollectDeviceEntityExt collectDeviceEntityExt = null;
        String show = HzhrTypeUtil.object2string(query.get("_show"));
        if (show != null) {
            collectDeviceEntityExt = collectDeviceDao.selectExt(queryModel2);
        }
        List<CollectDeviceEntityExt> list = new ArrayList<>();
        list.add(collectDeviceEntityExt);
        Concentrator_MeterGetModel result = collectDeviceCustomConvertor.extList2concentrator_MeterGetModel(list,null,ChangeCount,query);
        result.setChangeCount(ChangeCount);
        return result;
    }

    //region javadoc注释 : deleteByConcentratorIdAndId
    /**
     * 在用户所在物联设备公司下的集中器下删除表具 <br/><br/>
     * 简介 : 在用户所在物联设备公司下的集中器下删除表具 <br/>
     * 步骤 : <br/>
     * 1. 查询集中器：在用户所在的物联网公司下查询集中器,如果集中器不存在，抛出异常“集中器不存在” <br/>
     * 2. 删除表具：在集中器下删除指定表具 <br/>
     * 3. 发送指令到集中器：如果该集中器使用的是“重燃集中器协议”，须发送“删除下级表具”指令到集中器 <br/>
     * 4. 返回信息 <br/>
     * result.changeCount = 删除数量 <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/><br/>
     * @param concentratorId 集中器编号 <br/><br/>
     * @param id 编号 <br/><br/>
     * @throws ServiceException <br/>
     * @see Concentrator_MeterDeleteModel result <br/>
     */ 
    //endregion
    //region 说明 : deleteByConcentratorIdAndId
    //在用户所在物联设备公司下的集中器下删除表具
    //简介 : 在用户所在物联设备公司下的集中器下删除表具
    //步骤 :
    //1. 查询集中器：在用户所在的物联网公司下查询集中器,如果集中器不存在，抛出异常“集中器不存在”
    //2. 删除表具：在集中器下删除指定表具
    //3. 发送指令到集中器：如果该集中器使用的是“重燃集中器协议”，须发送“删除下级表具”指令到集中器
    //4. 返回信息
    //result.changeCount = 删除数量
    //endregion
    //region 参数 : deleteByConcentratorIdAndId
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "concentratorId", value = "集中器编号",required = true, dataType = "int", paramType = "path"),
            @ApiImplicitParam(name = "id", value = "编号",required = true, dataType = "int", paramType = "path"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),
    })
    //endregion
    //region 请求 : deleteByConcentratorIdAndId
    @RequestMapping(value = "/concentrators/{concentratorId}/meters/{id}", method = RequestMethod.DELETE)
    //endregion
    public Concentrator_MeterDeleteModel deleteByConcentratorIdAndId(Map<String, String> header, Integer concentratorId, Integer id,
                                                                     Map<String, Object> query) throws ServiceException {

        /* 查询集中器：在用户所在的物联网公司下查询集中器,如果集中器不存在，抛出异常“集中器不存在” */
        UserCardModel userCardModel = getUserCard(header);
        IotDeviceCustomQueryModel queryModel = iotDeviceCustomConvertor.iotDeviceService_query2queryModel(query);
        queryModel.setEqual_id(concentratorId);
        queryModel.setEqual_companyId(userCardModel.getCompanyId());
        queryModel.setEqual_categoryCode(deviceOptions.getCode("IOT_DEVICE_CATEGORY","CONCENTRATOR"));
        queryModel.setEqual_isValid("1");
        queryModel.setShow(true);
        IotDeviceEntityExt iotDevice_1 = iotDeviceDao.selectExt(queryModel);
        if (iotDevice_1 == null){
            throw new ServiceException(Device_ErrorsEnum.CONCENTRATOR_COMMANDSERVICE_GET_BY_CONCENTRATOR_ID_201);
        }

        /* 删除表具：在集中器下删除指定表具 */
        //查询目标表具的代码
        String code = collectDeviceDaoHelper.getCodeByIdAndIsValid(id, "1");

        CollectDeviceCustomQueryModel queryModel1 = new CollectDeviceCustomQueryModel();
        queryModel1.setEqual_id(id);
        queryModel1.setEqual_iotDeviceId(iotDevice_1.getId());
        queryModel1.setSet_isValid(CommonOptions.YES_NO.NO);
        queryModel1.setSet_updateTime(new Date());
        queryModel1.setSet_updateUserId(userCardModel.getUserId());
        int changeCount = collectDeviceDao.updateProps(queryModel1);

        /* 发送指令到集中器：如果该集中器使用的是“重燃集中器协议”，须发送“删除下级表具”指令到集中器 */
        String protocolId = iotDevice_1.getProtocolId();
        if (protocolId == null || protocolId.equals("2")) {
            Map<String, Object> query2 = new HashMap<>();
            DelMeterModel delMeterModel = new DelMeterModel();
            delMeterModel.setDeviceId(iotDevice_1.getIotPlatformDeviceId());
            delMeterModel.setMeterNo(code);
            collect_commandService.ccr_delMeter(initHeader(header, AccessModeEnum.GLOBAL), 2, query2, delMeterModel);
        }

        /* 返回信息 */
        Concentrator_MeterDeleteModel result = new Concentrator_MeterDeleteModel();
        result.setChangeCount(changeCount);
        return result;
    }

    //region javadoc注释 : getByConcentratorId
    /**
     * 查询用户所在物联网设备公司下的集中器下的表具 <br/><br/>
     * 简介 : 查询用户所在物联网设备公司下的集中器下的表具 <br/>
     * 步骤 : <br/>
     * 1. 查询集中器下的表具 : <br/>
     * 根据条件参数查询CollectDeviceEntityExt对象列表collectDeviceList_1及总数， <br/>
     * 额外查询条件如下： <br/>
     *           CollectDeviceEntityExt.categoryCode = deviceOptions.getCode('COLLECT_DEVICE_CATEGORY','LORA_METER')； <br/>
     *           CollectDeviceEntityExt.iotDeviceId = 路径参数concentratorId； <br/>
     *           CollectDeviceEntityExt.iotDeviceExt.companyId = 登录用户.companyId； <br/>
     * 2. 返回信息 : <br/>
     * 根据条件参数，将collectDeviceList_1及总数组装成结果对象并返回； <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_total : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示总数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _page : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 页数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _count : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 每页数量;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where Concentrator_MeterModel.id = #{_equal_id};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where Concentrator_MeterModel.code = #{_equal_code};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _like_des : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where Concentrator_MeterModel.des like #{_like_des} + '%';<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _greaterthanorequal_createTime : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where Concentrator_MeterModel.createTime >= #{_greaterthanorequal_createTime};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _lessthan_createTime : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where Concentrator_MeterModel.createTime < #{_less_createTime};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param concentratorId 集中器编号 <br/><br/>
     * @throws ServiceException <br/>
     * @see Concentrator_MeterGetModel result <br/>
     */ 
    //endregion
    //region 说明 : getByConcentratorId
    //查询用户所在物联网设备公司下的集中器下的表具
    //简介 : 查询用户所在物联网设备公司下的集中器下的表具
    //步骤 :
    //1. 查询集中器下的表具 :
    //根据条件参数查询CollectDeviceEntityExt对象列表collectDeviceList_1及总数，
    //额外查询条件如下：
    //          CollectDeviceEntityExt.categoryCode = deviceOptions.getCode('COLLECT_DEVICE_CATEGORY','LORA_METER')；
    //          CollectDeviceEntityExt.iotDeviceId = 路径参数concentratorId；
    //          CollectDeviceEntityExt.iotDeviceExt.companyId = 登录用户.companyId；
    //2. 返回信息 :
    //根据条件参数，将collectDeviceList_1及总数组装成结果对象并返回；
    //endregion
    //region 参数 : getByConcentratorId
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "concentratorId", value = "集中器编号",required = true, dataType = "int", paramType = "path"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_id", value = "筛选条件 : where Concentrator_MeterModel.id = #{equal_id}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_code", value = "筛选条件 : where Concentrator_MeterModel.code = #{equal_code}",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "like_des", value = "筛选条件 : where Concentrator_MeterModel.des like #{like_des} + '%'",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "greaterthanorequal_createTime", value = "筛选条件 : where Concentrator_MeterModel.createTime >= #{greaterthanorequal_createTime}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "lessthan_createTime", value = "筛选条件 : where Concentrator_MeterModel.createTime < #{less_createTime}",required = false, dataType = "int", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_id", value = "筛选条件 : where Concentrator_MeterModel.id = #{_equal_id}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_code", value = "筛选条件 : where Concentrator_MeterModel.code = #{_equal_code}",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_like_des", value = "筛选条件 : where Concentrator_MeterModel.des like #{_like_des} + '%'",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_greaterthanorequal_createTime", value = "筛选条件 : where Concentrator_MeterModel.createTime >= #{_greaterthanorequal_createTime}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_lessthan_createTime", value = "筛选条件 : where Concentrator_MeterModel.createTime < #{_less_createTime}",required = false, dataType = "int", paramType = "query"),

    })
    //endregion
    //region 请求 : getByConcentratorId
    @RequestMapping(value = "/concentrators/{concentratorId}/meters", method = RequestMethod.GET)
    //endregion
    public Concentrator_MeterGetModel getByConcentratorId(Map<String, String> header,Integer concentratorId, Map<String, Object> query) throws ServiceException {

        UserCardModel userCardModel = getUserCard(header);
        //1. 查询集中器下的表具
        CollectDeviceCustomQueryModel queryModel = collectDeviceCustomConvertor.collectDeviceService_query2queryModel(query);
        queryModel.setEqual_categoryCode(deviceOptions.getCode("COLLECT_DEVICE_CATEGORY","LORA_METER"));
        queryModel.setEqual_iotDeviceId(concentratorId);
        queryModel.setEqual_isValid("1");

        queryModel.setEqual_iotDeviceExt_companyId(userCardModel.getCompanyId());

        Boolean showInfo = HzhrTypeUtil.object2boolean(query.get("_show_info"));
        if (showInfo != null && showInfo) {
            queryModel.setShow(true);
        }

        String show = HzhrTypeUtil.object2string(query.get("_show"));
        List<CollectDeviceEntityExt> collectDeviceList_1 = null;
        if (show != null) {
             collectDeviceList_1 = collectDeviceDao.selectExtList(queryModel);
        }
        int total = 0;
        total = collectDeviceDao.selectCount(queryModel);

        //根据条件参数，将collectDeviceList_1及总数组装成结果对象并返回
        Concentrator_MeterGetModel result = collectDeviceCustomConvertor.extList2concentrator_MeterGetModel(collectDeviceList_1,total,null,query);

        return result;
    }

    //region javadoc注释 : getByConcentratorId1
    /**
     * 查询集中器下的表具 <br/><br/>
     * 简介 : 查询集中器下的表具 <br/>
     * 步骤 : <br/>
     * 1. 查询集中器下的表具 : <br/>
     * 根据条件参数查询CollectDeviceEntityExt对象列表collectDeviceList_1及总数， <br/>
     * 额外查询条件如下： <br/>
     *           CollectDeviceEntityExt.categoryCode = deviceOptions.getCode('COLLECT_DEVICE_CATEGORY','LORA_METER')； <br/>
     *           CollectDeviceEntityExt.iotDeviceId = 路径参数concentratorId； <br/>
     * 2. 返回信息 : <br/>
     * 根据条件参数，将collectDeviceList_1及总数组装成结果对象并返回； <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_total : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示总数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _page : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 页数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _count : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 每页数量;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where Concentrator_MeterModel.id = #{_equal_id};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where Concentrator_MeterModel.code = #{_equal_code};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _like_des : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where Concentrator_MeterModel.des like #{_like_des} + '%';<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _greaterthanorequal_createTime : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where Concentrator_MeterModel.createTime >= #{_greaterthanorequal_createTime};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _less_createTime : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where Concentrator_MeterModel.createTime < #{_less_createTime};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param concentratorId 集中器编号 <br/><br/>
     * @throws ServiceException <br/>
     * @see Concentrator_MeterGetModel result <br/>
     */ 
    //endregion
    //region 说明 : getByConcentratorId1
    //查询集中器下的表具
    //简介 : 查询集中器下的表具
    //步骤 :
    //1. 查询集中器下的表具 :
    //根据条件参数查询CollectDeviceEntityExt对象列表collectDeviceList_1及总数，
    //额外查询条件如下：
    //          CollectDeviceEntityExt.categoryCode = deviceOptions.getCode('COLLECT_DEVICE_CATEGORY','LORA_METER')；
    //          CollectDeviceEntityExt.iotDeviceId = 路径参数concentratorId；
    //2. 返回信息 :
    //根据条件参数，将collectDeviceList_1及总数组装成结果对象并返回；
    //endregion
    //region 参数 : getByConcentratorId1
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "concentratorId", value = "集中器编号",required = true, dataType = "int", paramType = "path"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_id", value = "筛选条件 : where Concentrator_MeterModel.id = #{equal_id}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_code", value = "筛选条件 : where Concentrator_MeterModel.code = #{equal_code}",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "like_des", value = "筛选条件 : where Concentrator_MeterModel.des like #{like_des} + '%'",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "greaterthanorequal_createTime", value = "筛选条件 : where Concentrator_MeterModel.createTime >= #{greaterthanorequal_createTime}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "less_createTime", value = "筛选条件 : where Concentrator_MeterModel.createTime < #{less_createTime}",required = false, dataType = "int", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_id", value = "筛选条件 : where Concentrator_MeterModel.id = #{_equal_id}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_code", value = "筛选条件 : where Concentrator_MeterModel.code = #{_equal_code}",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_like_des", value = "筛选条件 : where Concentrator_MeterModel.des like #{_like_des} + '%'",required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_greaterthanorequal_createTime", value = "筛选条件 : where Concentrator_MeterModel.createTime >= #{_greaterthanorequal_createTime}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_less_createTime", value = "筛选条件 : where Concentrator_MeterModel.createTime < #{_less_createTime}",required = false, dataType = "int", paramType = "query"),

    })
    //endregion
    //region 请求 : getByConcentratorId1
    @RequestMapping(value = "/v1/concentrators/{concentratorId}/meters", method = RequestMethod.GET)
    //endregion
    public Concentrator_MeterGetModel getByConcentratorId1(Map<String, String> header, Integer concentratorId, Map<String, Object> query) throws ServiceException {

        //1. 查询集中器下的表具

        CollectDeviceCustomQueryModel queryModel = collectDeviceCustomConvertor.collectDeviceService_query2queryModel(query);
        queryModel.setEqual_categoryCode(deviceOptions.getCode("COLLECT_DEVICE_CATEGORY","LORA_METER"));
        queryModel.setEqual_iotDeviceId(concentratorId);
        queryModel.setEqual_isValid("1");
        queryModel.setShow(true);
        Boolean showInfo = HzhrTypeUtil.object2boolean(query.get("_show_info"));
        if (showInfo != null && showInfo) {
            queryModel.setShow(true);
        }
        String show = HzhrTypeUtil.object2string(query.get("_show"));
        CollectDeviceEntityExt collectDeviceList_1 = null;
        if (show != null) {
             collectDeviceList_1 = collectDeviceDao.selectExt(queryModel);
        }
        List<CollectDeviceEntityExt> list = new ArrayList<>();
        list.add(collectDeviceList_1);
        Integer total = collectDeviceDao.selectCount(queryModel);
        Concentrator_MeterGetModel result = collectDeviceCustomConvertor.extList2concentrator_MeterGetModel(list,total,null,query);
        return result;
    }
}

